<template>
    <div class="app-container">
        <el-form :model="form">
            <el-form-item label="项目名称">
                <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="项目描述（每项描述以英文,分割）">
                <el-input v-model="form.description" type="textarea"></el-input>
            </el-form-item>
            <el-form-item label="链接">
                <el-input v-model="form.url"></el-input>
            </el-form-item>
            <el-form-item label="Github地址">
                <el-input v-model="form.github"></el-input>
            </el-form-item>
            <el-form-item label="预览图">
                <upload v-model="form.thumb" :style="{ width: '178px' }"></upload>
            </el-form-item>
            <el-form-item label="排序等级">
                <el-select v-model="form.order" placeholder="分类等级">
                    <el-option label="1" value="1"></el-option>
                    <el-option label="2" value="2"></el-option>
                    <el-option label="3" value="3"></el-option>
                    <el-option label="4" value="4"></el-option>
                    <el-option label="5" value="5"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="handleCancel">取 消</el-button>
            <el-button type="primary" @click="handleConfirmEdit">确认添加</el-button>
        </div>
    </div>
</template>

<script>
import Upload from "@/components/Upload/index.vue"
import { addProject } from "@/api/project.js"
export default {
    components: { Upload },
    data() {
        return {
            listLoading: false,
            data: [],
            form: {
                name: "",
                description: "",
                url: "",
                github: "",
                thumb: "",
                order: 1
            }
        }
    },
    methods: {
        async handleConfirmEdit() {
            const obj = { ...this.form }
            obj.description = this.form.description.split(",")
            obj.order = parseInt(this.form.order)
            await addProject(obj)
            this.$message.success("添加成功")
            this.$router.replace({ name: "projectList" })
        },
        handleCancel() {
            this.$router.replace({ name: "projectList" })
        }
    }
}
</script>

<style lang="less" scoped></style>
